﻿/*
 * PubMatic Inc. (“PubMatic”) CONFIDENTIAL
 * Unpublished Copyright (c) 2006-2014 PubMatic, All Rights Reserved.
 *
 * NOTICE:  All information contained herein is, and remains the property of PubMatic. The intellectual and technical concepts contained
 * herein are proprietary to PubMatic and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material is strictly forbidden unless prior written permission is obtained
 * from PubMatic.  Access to the source code contained herein is hereby forbidden to anyone except current PubMatic employees, managers or contractors who have executed 
 * Confidentiality and Non-disclosure agreements explicitly covering such access.
 *
 * The copyright notice above does not evidence any actual or intended publication or disclosure  of  this source code, which includes  
 * information that is confidential and/or proprietary, and is a trade secret, of  PubMatic.   ANY REPRODUCTION, MODIFICATION, DISTRIBUTION, PUBLIC  PERFORMANCE, 
 * OR PUBLIC DISPLAY OF OR THROUGH USE  OF THIS  SOURCE CODE  WITHOUT  THE EXPRESS WRITTEN CONSENT OF PubMatic IS STRICTLY PROHIBITED, AND IN VIOLATION OF APPLICABLE 
 * LAWS AND INTERNATIONAL TREATIES.  THE RECEIPT OR POSSESSION OF  THIS SOURCE CODE AND/OR RELATED INFORMATION DOES NOT CONVEY OR IMPLY ANY RIGHTS  
 * TO REPRODUCE, DISCLOSE OR DISTRIBUTE ITS CONTENTS, OR TO MANUFACTURE, USE, OR SELL ANYTHING THAT IT  MAY DESCRIBE, IN WHOLE OR IN PART.                
 */


using System;
using System.Collections.Generic;

namespace com.moceanmobile.mast.mraid
{
    public class OrientationProperties
    {
        public static OrientationProperties PropertiesFromArgs(Dictionary<string, string> args)
        {
            OrientationProperties properties = new OrientationProperties();

            string value = null;

            if ((args.TryGetValue("allowOrientationChange", out value)) && (value == Const.True))
            {
                properties.allowOrientationChange = true;
            }
            else
            {
                properties.allowOrientationChange = false;
            }

            if (args.TryGetValue("forceOrientation", out value))
            {
                switch (value)
                {
                    case Const.OrientationPropertiesForceOrientationNone:
                        properties.forceOrientation = ForceOrientation.None;
                        break;
                    case Const.OrientationPropertiesForceOrientationPortrait:
                        properties.forceOrientation = ForceOrientation.Portrait;
                        break;
                    case Const.OrientationPropertiesForceOrientationLandscape:
                        properties.forceOrientation = ForceOrientation.Landscape;
                        break;
                }
            }

            return properties;
        }

        private bool allowOrientationChange = true;
        public bool AllowOrientationChange
        {
            get { return this.allowOrientationChange; }
            set { this.allowOrientationChange = value; }
        }

        private ForceOrientation forceOrientation = ForceOrientation.None;
        public ForceOrientation ForceOrientation
        {
            get { return this.forceOrientation; }
            set { this.forceOrientation = value; }
        }

        public override string ToString()
        {
            string allowOrientationChangeString = Const.False;
            if (this.allowOrientationChange)
                allowOrientationChangeString = Const.True;

            string forceOrientationString = string.Empty;
            switch (this.forceOrientation)
            {
                case ForceOrientation.None:
                    forceOrientationString = Const.OrientationPropertiesForceOrientationNone;
                    break;
                case ForceOrientation.Portrait:
                    forceOrientationString = Const.OrientationPropertiesForceOrientationPortrait;
                    break;
                case ForceOrientation.Landscape:
                    forceOrientationString = Const.OrientationPropertiesForceOrientationLandscape;
                    break;
            }

            string ret = string.Format("{{allowOrientationChange:{0},forceOrientation:\"{1}\"}}",
                allowOrientationChangeString, forceOrientationString);

            return ret;
        }
    }
}
